//
//  AddressListViewController.m
//  XinKaiFa55like
//
//  Created by 55like on 2017/9/23.
//  Copyright © 2017年 55like lj. All rights reserved.
//

#import "AddressListViewController.h"
#import "SetCityViewController.h"


@interface AddressListViewController ()

@property (nonatomic,strong)UILabel * titleLab;
@property (nonatomic,strong)UILabel * addressLab;
@property (nonatomic,strong)UIImageView * icon;
@property (nonatomic,strong)NSMutableDictionary * allData;
@property (nonatomic,copy)void(^block)();

@end

@implementation AddressListViewController
{
    
    UIButton * bcview;
    
}
-(NSMutableDictionary *)allData{
    
    if (!_allData) {
        
        _allData = [[NSMutableDictionary alloc]init];
        
    }
    
    return _allData;
}
- (void)viewDidLoad {
    [super viewDidLoad];
   
    bcview = [[UIButton alloc]initWithFrame:CGRectMake(0, 64+10, kScreenWidth, 60)];
    bcview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bcview];
    [bcview addTarget:self action:@selector(setAddress) forControlEvents:UIControlEventTouchUpInside];
    
    self.allData = self.userInfo;
    self.block = self.otherInfo[@"block"];
    
    self.icon = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth - 10 - 35/2, 0, 35/2, 35/2)];
    self.icon.image = [UIImage imageNamed:@"xkf_zyicon"];
    [bcview addSubview:self.icon];
    
    self.titleLab = [RHMethods labelWithFrame:CGRectMake(10, 12, X(self.icon) - 10 - 10, 12) font:Font(14) color:rgbTitleDeepGray text:[NSString stringWithFormat:@"%@  %@",[self.allData valueForJSONStrKey:@"addname"],[self.allData valueForJSONStrKey:@"addtel"]]];
    [bcview addSubview:self.titleLab];
    
    self.addressLab = [RHMethods labelWithFrame:CGRectMake(10, YH(self.titleLab) + 10, X(self.icon) - 10 - 10, 12) font:Font(14) color:rgbTxtGray text:[NSString stringWithFormat:@"%@%@%@%@",[self.allData valueForJSONStrKey:@"province"],[self.allData valueForJSONStrKey:@"city"],[self.allData valueForJSONStrKey:@"area"],[self.allData valueForJSONStrKey:@"address"]]];
    self.addressLab.numberOfLines = 0;
    [bcview addSubview:self.addressLab];
    
    self.addressLab.frameHeight = [self.addressLab.text HEIGHTwF:14 W:X(self.icon) - 10 - 10];
    bcview.frameHeight = YH(self.addressLab) + 10;
    self.icon.frameY = (bcview.frameHeight - 35/2)/2;
    
    [self makeData];
    
    
}
-(void)makeData{
    
    
    self.titleLab.text = [NSString stringWithFormat:@"%@  %@",[self.allData valueForJSONStrKey:@"addname"],[self.allData valueForJSONStrKey:@"addtel"]];
    self.addressLab.text = [NSString stringWithFormat:@"%@%@%@%@",[self.allData valueForJSONStrKey:@"province"],[self.allData valueForJSONStrKey:@"city"],[self.allData valueForJSONStrKey:@"area"],[self.allData valueForJSONStrKey:@"address"]];
    self.addressLab.frameHeight = [self.addressLab.text HEIGHTwF:14 W:X(self.icon) - 10 - 10];
    bcview.frameHeight = YH(self.addressLab) + 10;
    self.icon.frameY = (bcview.frameHeight - 35/2)/2;
    

    if (self.addressLab.text.length == 0) {
        
        self.titleLab.text = @"";
        
    }
}
-(void)setAddress{
    
    EMWeakSelf(weakSelf);
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:^(NSMutableDictionary * data){
        
        weakSelf.allData = data;
        [weakSelf makeData];
        
        
    } forKey:@"dataBlock"];
    [dic setValue:self.block forKey:@"block"];
    [self pushController:[SetCityViewController class] withInfo:self.allData withTitle:@"修改地址" withOther:dic];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
